Conditional Statement
Q1.
Consider the following ANSI C program. #include < stdio.h > int main() { int i, j, count; count=0; i=0; for (j=-3; j < =3; j++) { if (( j > = 0) && (i++)) count = count + j; } count = count +i; printf("%d", count); return 0; }Which one of the following options is correct?Q2.
What is the output of tho following program? main(){ int x=2, y=5; if(x < y) return (x=x+y); else printf("z1"); printf("z2"); }Q3.
Assume A and B are non-zero positive integers. The following code segment: while(A!=B){ if(A > B) A -= B; else B -= A; } cout << A; // printing the value of AQ4.
Let x be an integer which can take a value of 0 or 1. The statement if (x == 0) x = 1; else x = 0; is equivalent to which one of the following ?Q5.
Consider the C program below. #include < stdio.h > int *A, stkTop; int stkFunc(int opcode, int val) { static int size=0, stkTop=0; switch (opcode) { case -1: size = val; break; case 0: if (stkTop < size) A[stkTop++] = val; break; default: if (stkTop) return A[--stkTop]; } return -1; } int main() { int B[20]; A = B; stkTop = -1; stkFunc (-1, 10); stkFunc ( 0, 5); stkFunc ( 0, 10); printf ("%d\n", stkFunc(1, 0) + stkFunc(1, 0)); } The value printed by the above program is __________.Q6.
Given the programming constructs I. assignment II. for loops where the loop parameter cannot be changed within the loop III. if-then-else IV. forward go to V. arbitrary go to VI. non-recursive procedure call VII. recursive procedure/function call VIII. repeat loop, which constructs will you not include in a programming language such that it should be possible to program the terminates (i.e., halting) function in the same programming languageQ8.
What will be the output of the following C program segment? char inChar = 'A' ; switch ( inChar ) { case 'A' : printf ("Choice A\ n") ; case 'B' : case 'C' : printf ("Choice B") ; case 'D' : case 'E' : default : printf ( " No Choice" ) ; }Q9.
Consider the following pseudo-codex:=1; i:=1; while (x <= 1000) begin x:=2^x; i:=i+1; end; What is the value of i at the end of the pseudo-code?Q10.
Consider the following pseudocodex:=1; i:=1; while ( x \leq 500 ) begin x:=2^x; i:=i+1; end What is the value of i at the end of the pseudocode?